<?php
// ----------------------------------------------------------------------
// pn-commerce Shopping Cart Solution for PostNuke
// http://pncommerce.de
// http://www.sourceforge.net/projects/pn-commerce/
//
// It is based on PostKart 0.701QA from
//			Destin LeBlanc [ postkart@zenflesh.com ]
// ----------------------------------------------------------------------
// Source file:  $Source: /cvsroot/pn-commerce/pn-commerce/pnfmorder1testapi.php,v $
//
// Last changes from:  $Author: landseer $
//
// Revision:           $Revision: 1.5 $
//
// Date of revision    $Date: 2003/11/30 13:17:26 $
//  
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------

/**
 * getConfig
 *@param  none
 *@return array of config values
 */
function pncommerce_fmorder1testapi_getConfig()
{
    $data = pnModGetVar ( 'pncommerce', 'fmorder1testData' );
    if( isset( $data ) )
    {
        return unserialize( $data );
    }
    return false;
}

/**
 * setConfig
 *@param  $args array of config values
 *@return none
 */
function pncommerce_fmorder1testapi_setConfig( $args )
{
    pnModSetVar ( 'pncommerce', 'fmorder1testData', serialize( $args ) );
    return true;
}

/**
 * configuration
 *
 */
function pncommerce_fmorder1testapi_configuration()
{
    if( !pnModAPILoad( 'pncommerce', 'admin' ) )
    {
        return false;
    }
    if( !pnModAPILoad( 'pncommerce', 'user' ) )
    {
        return false;
    }

    if (!pnSecAuthAction(0, 'pncommerce::', '::', ACCESS_ADMIN))
    {
        return pnModAPIFunc( 'pncommerce', 'admin', 'GetErrorPage',array('Title'=>_PNC_NOAUTH));
    }

    $config = pncommerce_fmorder1testapi_getConfig();

    $submit = pnVarCleanFromInput( 'submit' );
    
    if( !$submit )
    {
        $smarty = new pnRender();
        $smarty->caching = false;
        $smarty->assign('Config',$config );
        return $smarty->fetch( "pncommerce_fmorder1test_configuration.html" );
    }
    else   // submit is set
    {
	    $config['order1test'] = pnVarCleanFromInput('order1test');
	    pncommerce_fmorder1testapi_setConfig( $config );
	    pnRedirect( pnModAPIFunc( 'pncommerce','user','pncModURL',
								  array('Module'=>'pncommerce', 'Section'=> 'admin', 'Function'=>'ModificationConfig')));
	    return true;
    }

}

/**
 * checkout
 *@param $args['cart'] array complete array with cart data
 *@return array with cart data
 */
function pncommerce_fmorder1testapi_checkout($args)
{
    // user data can be read from PNCUserData if needed
    extract( $args );
    $config = pncommerce_fmorder1testapi_getConfig();
    
    $modifier = array();
    $modifier['order1test'] = $config['order1test'];
    array_push( $cart['OrderModifiers'], $modifier );
    return 0;
}

/**
 * info
 *
 */
function pncommerce_fmorder1testapi_info()
{
    return ( "Order 1 Test" );
}

/**
 * type
 *
 */
function pncommerce_fmorder1testapi_type()
{
    return ( _PNC_MODIFIERPERORDER );
}

/**
 * FooterMsg
 *
 */
function pncommerce_fmorder1testapi_FooterMsg()
{
    return false;
}

/**
 * installation
 *
 *@param $args['Mode'] string  instal, remove activate or deactivate
 *
 */
function pncommerce_fmorder1testapi_installation($args)
{
    extract( $args );
    $Mode = pnVarCleanFromInput( 'Mode' );
    if( !pnModAPILoad( 'pncommerce', 'admin' ) )
    {
        return false;
    }

    if (!pnSecAuthAction(0, 'pncommerce::', '::', ACCESS_ADMIN))
    {
        return pnModAPIFunc( 'pncommerce', 'admin', 'GetErrorPage',array('Title'=>_PNC_NOAUTH));
    }
    
    switch( $Mode )
    {
        case 'install':
                    pnModSetVar( 'pncommerce', 'fmorder1test', 'on' );
                    pnModSetVar( 'pncommerce', 'fmorder1testData', serialize( array( 'Amount' => 0 ) ) );
                    pnModAPIFunc( 'pncommerce', 'admin', 'addtoModifierSequence', 
                                  array( 'Modifier' => 'fmorder1test',
                                         'type'     => 'order' ) );
                    break;
        case 'remove':
                    pnModDelVar( 'pncommerce', 'fmorder1test' );
                    pnModDelVar( 'pncommerce', 'fmorder1testData' );
                    pnModAPIFunc( 'pncommerce', 'admin', 'removefromModifierSequence',
                                  array( 'Modifier' => 'fmorder1test',
                                         'type'     => 'order' ) );
                    break;
        case 'activate':
                    pnmodSetVar( 'pncommerce', 'fmorder1test', 'on' );
                    break;
        case 'deactivate':
                    pnModSetVar( 'pncommerce', 'fmorder1test', 'off' );
                    break;
        default:
                    return false;
    }
    pnRedirect( pnModAPIFunc( 'pncommerce','user','pncModURL',
                              array('Module'=>'pncommerce', 'Section'=> 'admin', 'Function'=>'ModificationConfig')));
    return true; 
}               


?>